package com.huawei.appgallery.foundation.ui.framework.cardkit.widget;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import com.huawei.appgallery.foundation.ui.css.CSSRule;
import com.huawei.appgallery.foundation.ui.css.CSSView;
import java.lang.ref.WeakReference;
import java.util.ArrayList;
import java.util.List;
import o.ccn;
import o.chy;
import o.chz;
import o.cia;
import o.cia.c;
import o.cib;
import o.cid;
import o.cie;
import o.cig;
import o.cij;

public class CardListAdapter extends BaseAdapter implements c, cij {
    private static final String TAG = "CardListAdapter";
    private chy cardEventListener;
    protected Context context;
    private LayoutInflater inflater;
    private WeakReference<cid> lazyLoadedViewRef;
    private List<cie> nodeList = null;
    protected cia provider;
    private cig refreshListener;

    public CardListAdapter(Context context, cia o_cia) {
        this.context = context;
        this.inflater = LayoutInflater.from(context);
        this.provider = o_cia;
        this.provider.ॱ((c) this);
        this.nodeList = new ArrayList();
    }

    public chy getCardEventListener() {
        return this.cardEventListener;
    }

    public cig getRefreshListener() {
        return this.refreshListener;
    }

    public void setCardEventListener(chy o_chy) {
        this.cardEventListener = o_chy;
    }

    public void setRefreshListener(cig o_cig) {
        this.refreshListener = o_cig;
    }

    public boolean hasMore() {
        if (this.provider != null) {
            return this.provider.ᐝ();
        }
        return false;
    }

    public int getCount() {
        return this.provider.ˊॱ();
    }

    public Object getItem(int i) {
        return null;
    }

    public long getItemId(int i) {
        return (long) i;
    }

    public int getItemViewType(int i) {
        if (this.provider.ॱˋ()) {
            chz ˏ = this.provider.ˏ(i);
            if (ˏ != null) {
                return ˏ.ᐝ();
            }
        }
        return this.provider.ˎ(i);
    }

    public int getViewTypeCount() {
        return cib.ˏ();
    }

    public View getView(int i, View view, ViewGroup viewGroup) {
        chz ˏ = this.provider.ˏ(i);
        if (ˏ != null) {
            ˏ.ˎ(this.provider.ʻ);
            if (i == 0) {
                ˏ.ˎ(true);
            } else {
                ˏ.ˎ(false);
            }
            if (isNeedCreateItemView(view)) {
                View createItemView = createItemView(i, null, viewGroup);
                if (createItemView == null) {
                    createItemView = new View(this.context);
                    ccn.ˏ.ˏ(TAG, "getView, convertView == null");
                }
                cssRender(createItemView, ˏ.ʻ());
                view = createItemView;
            }
        }
        cie o_cie = (cie) view.getTag();
        if (this.lazyLoadedViewRef != null) {
            cid o_cid = (cid) this.lazyLoadedViewRef.get();
            if (!(o_cid == null || o_cie == null)) {
                o_cie.ʽ = o_cid.ʽʼ() == 0;
            }
        }
        if (o_cie != null) {
            if (ˏ != null) {
                o_cie.ॱ(ˏ, viewGroup);
            }
            o_cie.ˏ(i);
        }
        return view;
    }

    protected boolean isNeedCreateItemView(View view) {
        return view == null;
    }

    public View createItemView(int i, View view, ViewGroup viewGroup) {
        cie ˋ = cib.ˋ(this.context, this.provider.ˎ(i));
        if (ˋ != null) {
            return createView(ˋ, viewGroup);
        }
        ccn.ˏ.ˏ(TAG, "createItemView, node == null");
        return new View(this.context);
    }

    public View createView(cie o_cie, ViewGroup viewGroup) {
        ViewGroup ˊ = o_cie.ˊ(this.inflater, null);
        if (o_cie.ˊ(ˊ, viewGroup)) {
            o_cie.ˋ(this.cardEventListener);
            o_cie.ˊ(this.refreshListener);
            ˊ.setTag(o_cie);
            o_cie.ॱˊ();
            this.nodeList.add(o_cie);
        }
        return ˊ;
    }

    public void cssRender(View view, CSSRule cSSRule) {
        if (view != null && cSSRule != null) {
            CSSView.wrap(view, cSSRule).render();
        }
    }

    public void onDataUpdated() {
        notifyDataSetChanged();
    }

    public void setLazyLoadedPage(cid o_cid) {
        this.lazyLoadedViewRef = new WeakReference(o_cid);
    }

    public void destroy() {
        if (this.nodeList != null) {
            destroyNodes();
            this.nodeList.clear();
            this.nodeList = null;
        }
    }

    protected void destroyNodes() {
        for (cie o_cie : this.nodeList) {
            if (o_cie != null) {
                o_cie.ॱˎ();
            }
        }
    }
}
